home *** CD-ROM | disk | FTP | other *** search
- Path: easy.in-chemnitz.de!mkmk!floh
- From: floh@mkmk.in-chemnitz.de (Andre Weissflog)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: simple K&R ANSI-C examples won't compile under SAS/C
- Message-ID: <inOay*mG0@mkmk.in-chemnitz.de>
- Date: Fri, 01 Mar 1996 20:57:54 CET
- Reply-To: floh@mkmk.in-chemnitz.de
- References: <68771782@0humpty.tomate.tng.oche.de>
- Distribution: world
- Organization: private uucp site
- X-Newsreader: Arn V 1.04
-
- In article <68771782@0humpty.tomate.tng.oche.de>, Andreas Mixich writes:
-
- >
- > Hi,
- >
- > this little example form the 'Kernighan&Ritchie' won't compile:
- >
- > #include <stdio.h>
- > #include <clib/alib_stdio_protos.h>
- >
- > main()
- > {
- > int c;
- >
- > while((c = GetChar()) !=EOF)
- > PutChar(c);
- > }
- >
- > Yes, *you* laugh now, but for me this is really strange.
- >
- > I get an error #72 in alib_stdio_protos.h; conflict with previous declaration,
- > see file stdio.h.
- >
-
- Easy. In <stdio.h> e.g. the printf() prototype is defined as
-
- extern int printf(const char *, ...);
-
- in <clib/alib_stdio_protos.h> as
-
- LONG printf( STRPTR fmt, ... );
-
-
- The same function is declared twice with different
- parameter types, thus the compiler error.
-
- Now to the real problems:
-
- 1st) The prototypes in alib_stdio_protos.h are Amiga-ized
- replacement functions for some of ANSI-C's stdio
- functions. You can either use the stdio functions
- that came with your compiler, *or* the ones
- in amiga.lib. But not both in the same code.
-
- The ANSI stdio replacement functions in amiga.lib are
- IMHO only of limited use for the following reasons
- (amongst others):
-
- - formatted string output goes through
- exec.library/RawDoFmt(), which is not
- fully compatible to and not as powerful as
- ANSI's formatting
- - no cleanup at exit() for open file handles
- - amiga.lib stdio file handles can't be mixed
- with the file handles of your compilers
- stdio functions
- - extra care must be taken to link amiga.lib before
- c.lib
-
- The only advantage is that your executables can
- become drastically smaller, since you don't need
- the compilers IO startup/cleanup code, and
- there's much less additional code linked
- to your program.
-
- *BUT* in that case you're better going with
- dos.library's "look-a-likes" (Printf() for instance,
- note the 'P').
-
- 2nd) GetChar() and PutChar() are not ANSI C functions,
- the correct names are getchar() and putchar().
- Thus your program should look like:
-
- #include <stdio.h>
-
- int main(void)
- {
- int c;
- while((c = getchar()) != EOF) putchar(c);
- return 0;
- }
-
- > Now, I have read the guide on this error, but if I leave out the
- > alib_stdio_protos.h, this will cause the error, no Prototype for function
- > getchar() (or so).
-
- Nope :-)
- If you leave out alib_stdio_protos.h, the compiler will give
- you a warning that there's no prototype for GetChar(). But
- the correct name would be getchar() (and that one is defined
- in stdio.h).
-
- > Also, if I do a c = GetChar(void) (as synopsis description in sclib.guide
- > shows) the error still ocuures.
- >
- GetChar() != getchar()
-
- C is always case sensitiv.
-
- Bye,
- -Floh.
-
- ====//=== Andre Weissflog <floh@mkmk.in-chemnitz.de> =======
- ...// Sep'95: Return Of The Living Death...................
- \\// 90% of everything is crap (Sturgeon's Law)...........
- =\\===============================================Amiga!=
-
-